import {
  getList,
  addList
} from '../../api/index.js';
Page({
  data: {
    list: []
  },
  onLoad() {
    this.getListData();
  },
  onShow() {
    const refresh = getApp().globalData.refresh;
    if (refresh) this.getListData();
  },
  async getListData() {
    wx.showLoading({
      title: '加载中...',
      mask: true
    })
    let res = await getList().then(res => res).catch(err => err)
    this.setData({
      list: res.data || []
    })
    wx.hideLoading();
  },
  async addListData() {
    wx.showLoading({
      title: '提交中...',
      mask: true
    })
    await addList({
      title: '标题2',
      time: '15:05',
      date: '2023-12-15',
      content: '测试内容'
    }).then(res => res).catch(err => err);
    this.getListData();
    wx.hideLoading();
  },
  navigateTo(e) {
    const {
      type = "", id = ""
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/details/index?type=${type}&id=${id}`
    })
  }
});